package com.code.user.controller;


import com.code.common.annotation.Idempotent;
import com.code.common.model.ResultVO;
import com.code.user.service.AccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

/**
 * <p>
 * 账号表 前端控制器
 * </p>
 *
 * @author Yan
 * @since 2023-04-14
 */
@Api(value = "账号控制器", description = "账号控制器")
@RestController
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @ApiOperation(value = "快速登录", notes = "快速登录")
    @PostMapping("/login")
    @Idempotent
    public ResultVO quickLogin(Principal principal) throws HttpRequestMethodNotSupportedException {
        ResponseEntity<OAuth2AccessToken> entity = accountService.login(principal);
        return ResultVO.OK(entity.getBody());
    }

}
